<?php
include_once('common/header.php');
if($AppUI->id <=0 || ($AppUI->id > 0 && $AppUI->type < 1)) {
	$this->_redirect(HOST_BACKEND);
}
$arrParams 		= $objRequest->getParams();
$intAction		= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$arrAdminId		= isset($arrParams['padminid']) ? $arrParams['padminid'] : null;
$arrUsername	= isset($arrParams['pusername']) ? $arrParams['pusername'] : null;

$intError		= 0;
$intMessage		= 0;
if($intAction > 0) {
	switch($intAction) {
		case 1:
			if(isset($_SESSION['admin']) && (($_SESSION['admin']&1<<5)>0)) {
				if($arrAdminId) {
					$objAdmin = new Admin();
					$intError = $objAdmin->updateStatus($AppUI->id, Ecore_Function::convertArrToStr($arrAdminId), 32);
					if($intError == 0) {
						foreach($arrAdminId as $row) {
							$objCache->clear->deleteAdminById($row);
							$objCache->clear->deleteAdminByUsername($arrUsername[$row]);
						}
						$intMessage	= 5;
					}
					else {
						$intError = 17;
					}
				}
				else {
					$intError = 19;
				}
			} else {
				$intError = 17;
			}
			break;
		case 3:
			if(isset($_SESSION['admin']) && (($_SESSION['admin']&1<<4)>0)) {
				if($arrAdminId) {					
					$objAdmin = new Admin();
					$intError = $objAdmin->updateStatus($AppUI->id, Ecore_Function::convertArrToStr($arrAdminId), 16);
					if($intError == 0) {
						foreach($arrAdminId as $row) {
							$objCache->clear->deleteAdminById($row);
							$objCache->clear->deleteAdminByUsername($arrUsername[$row]);
						}
						$intMessage	= 4;
					} else {
						$intError = 16;
					}
				}
				else {
					$intError = 19;
				}
			} else {
				$intError = 16;
			}
			break;
	}
} else {
	$intError = 18;
}
if($intError > 0) {
	Ecore_Function::setError($arrError[$intError]);
} else {
	Ecore_Function::setMsg($arrMessage[$intMessage]);
}
$this->_redirect(HOST_BACKEND . 'admin/index');
